//
//  ViewController.m
//  LAMapBasicDemo
//
//  Created by 罗亮富 on 2017/4/8.
//  Copyright © 2017年 2Bulu. All rights reserved.
//

#import "ViewController.h"
#import "LAGBaseMapViewController.h"
#import <ImageIO/ImageIO.h>
#import <CoreLocation/CoreLocation.h>

#import "LAGTrackPolyLineCreater.h"
#import <mach/mach.h>
#import <malloc/malloc.h>
#import "GeoData+Relationships.h"
#import "LAGImageConvertViewController.h"
#import <MapGisBusiness/MapGisBusiness.h>
#import <MapBasics/MapBasics.h>


NS_INLINE double nearDistanceBetweenPoints1(LocationPointType p1, LocationPointType p2)
{
    double delX = fabs(p2.longitude - p1.longitude);
    double delY = fabs(p2.latitude - p1.latitude);
    double ref = delX;
    float k;
    if(delY > delX)
    {
        k = delX/delY;
        ref = delY;
    }
    else
        k = delY/delX;
    
    if(k>0.9)
        return 1.4*ref;
    if(k>0.75)
        return 1.3*ref;
    if(k>0.57)
        return 1.2*ref;
    if(k>0.32)
        return 1.1*ref;
    
    return ref;
}
NS_INLINE double exactDistanceBetweenPoints1(LocationPointType p1, LocationPointType p2)
{
    return sqrt(pow(p2.longitude - p1.longitude, 2)+pow(p2.latitude - p1.latitude, 2));
}

void report_memory(void)
{
    struct task_basic_info info;
    mach_msg_type_number_t size = sizeof(info);
    kern_return_t kernr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
    
    if (kernr == KERN_SUCCESS) {
        printf("MEMORY IS :%f\n\n", info.resident_size/(1024.0 * 1024.0));
    }
    else {
        printf("MEMORY ERROR:%s\n\n", mach_error_string(kernr));
    }
}


@interface ViewController ()

@end

@implementation ViewController
{
    CLLocationManager *_lcMg;
    NSMutableArray *_mArray;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blueColor];
    
    self.title = NSLocalizedString(@"TITLE_MAIN", nil);
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 100, 160, 40);
    btn.center = CGPointMake(self.view.frame.size.width/2, btn.center.y);
    [btn setTitle:NSLocalizedString(@"BTN_SURE", nil) forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor yellowColor]];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    
    [btn addTarget:self action:@selector(doSth:) forControlEvents:UIControlEventTouchUpInside];
    
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 150, 140, 40);
    btn.center = CGPointMake(self.view.frame.size.width/2, btn.center.y);
    [btn setTitle:NSLocalizedString(@"Test", nil) forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor yellowColor]];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    
    [btn addTarget:self action:@selector(doSth1:) forControlEvents:UIControlEventTouchUpInside];
    
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 200, 200, 40);
    btn.center = CGPointMake(self.view.frame.size.width/2, btn.center.y);
    [btn setTitle:NSLocalizedString(@"doSth2", nil) forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor yellowColor]];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    
    [btn addTarget:self action:@selector(doSth2:) forControlEvents:UIControlEventTouchUpInside];
    
    UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(0, 300, self.view.frame.size.width, 400)];
    tv.editable = YES;
    tv.allowsEditingTextAttributes = YES;
    tv.text = @"Hello Roen, how are you today? 我很好谢谢，你什么时候回来啊？very nice of course";
    [self.view addSubview:tv];
    
  //  UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textViewDetect:)];
  //  [tv addGestureRecognizer:tap];
    
    _lcMg = [[CLLocationManager alloc] init];
    [_lcMg startUpdatingLocation];
    

}


-(IBAction)doSth:(id)sender
{

  //  NSString *path = [[NSBundle mainBundle]pathForResource:@"track53413778959516807249" ofType:@"Points"];//点数多
 //   NSString *path = [[NSBundle mainBundle]pathForResource:@"track537934958142195400260557" ofType:@"Points"];//轨迹点少
 //   NSString *path = [[NSBundle mainBundle]pathForResource:@"track53587B55516881144108930272" ofType:@"Points"];
 //   TrackSegment *seg = [(NSArray *)[NSKeyedUnarchiver unarchiveObjectWithFile:path] firstObject];
//
  //  ValueAddedTrackPolyLine *line = [seg polyLineWith2ndValueType:2 ofCoordinateSysytem:LACoordinateSystemGCJ02 createIfNotExist:YES];
   // TrackPolyline *line = [LAGTrackPolyLineCreater cachedPolyLineForTrackSegment:seg with3rdValueType:2 ofCoordinateSysytem:LACoordinateSystemGCJ02 mapRegion:NULL];
//    line.minRefValue = 100;
//    line.midRefValue = 200;
//    line.maxRefValue = 1000;
 //   line.startPointMarkText = @"Start";
 //   line.endPointMarkText = @"终";
//    CLLocationCoordinate2D p[2];
//    p[0] = CLLocationCoordinate2DMake(23.3, 110.4);
//    p[1] = CLLocationCoordinate2DMake(23.2, 111.2);
//    LATextPolyline *line = [LATextPolyline polylineWithCoordinates:p count:2];
//    line.textColor = [UIColor greenColor];
//    line.lineDashPattern = @[[NSNumber numberWithInteger:5],[NSNumber numberWithInteger:5]];
//    line.text = @"LAStraightPolyLine";
    
    LAGBaseMapViewController *vc = [LAGBaseMapViewController new];
    [self.navigationController pushViewController:vc animated:YES];

}

-(IBAction)doSth1:(UIButton *)btn
{
    LAGImageConvertViewController *vc = [[LAGImageConvertViewController alloc]init];
    
    [self.navigationController pushViewController:vc animated:YES];
}

-(IBAction)doSth2:(UIButton *)btn
{

}

#define radiansToDegrees( radians ) ( ( radians ) * ( 180.0 / M_PI ) )
-(void)prepareForInterfaBuilder000:(TrackSegment *)seg
{
}


@end


